package org.mp3weezel.strands.services;

import java.util.HashMap;
import java.util.Map;

import org.mp3weezel.strands.StrandsAPI;
import org.mp3weezel.strands.StrandsServiceException;
import org.mp3weezel.strands.domain.User;
import org.mp3weezel.strands.domain.UserList;

/**
 * Account services enable you to programmatically update your MyStrands
 * account.
 * 
 * @author Christian Humer
 */
public class AccountService extends AbstractService {

	public AccountService(StrandsAPI api) {
		super(api);
	}

	public UserList userValidate(String username, String password)
			throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("username", new String[] { username });
		parameter.put("password", new String[] { password });
		return (UserList) request("/user/validate", parameter);
	}

	public int userUpdateEmail(String username, String password,
			String email, String emailRepeat) throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("username", new String[] { username });
		parameter.put("password", new String[] { password });
		parameter.put("email", new String[] { email });
		parameter.put("emailRepeat", new String[] { emailRepeat });
		return requestHttp("/user/update/email", parameter);
	}

	public int userUpdatePassword(String username, String password,
			String newPassword, String newPasswordRepeat)
			throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("username", new String[] { username });
		parameter.put("password", new String[] { password });
		parameter.put("newPassword", new String[] { newPassword });
		parameter.put("newPasswordRepeat", new String[] { newPasswordRepeat });
		return requestHttp("/user/update/password", parameter) ;
	}

	public int userUpdateShareProfile(String username, String password,
			boolean shareProfile) throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("username", new String[] { username });
		parameter.put("password", new String[] { password });
		parameter.put("shareProfile", new String[] { shareProfile ? "true"
				: "false" });
		return requestHttp("/user/update/shareprofile", parameter);
	}

	public int userUpdateAlias(String username, String password,
			String alias) throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("username", new String[] { username });
		parameter.put("password", new String[] { password });
		parameter.put("alias", new String[] { alias });
		return requestHttp("/user/update/alias", parameter);
	}

	public User userLookupProfile(String username, String password)
			throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("username", new String[] { username });
		parameter.put("password", new String[] { password });
		return (User) request("/user/lookup/profile", parameter);
	}

}
